﻿using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore;

namespace SBlogCore.Common.DatabaseAccessor.Repositorys.EFCore
{
    [SkipScan]
    public partial interface IRepository<TEntity> where TEntity : class, IBaseEntity
    {
        /// <summary>
        /// 实体
        /// </summary>
        DbSet<TEntity> Entities { get; init; }
        /// <summary>
        /// 不跟踪
        /// </summary>
        IQueryable<TEntity> DetachedEntities { get; }

        /// <summary>
        /// 条件查询
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        IQueryable<TEntity> Where(Expression<Func<TEntity, bool>> predicate);
        /// <summary>
        /// 提交变化
        /// </summary>
        /// <returns></returns>
        int SaveChanges();
        /// <summary>
        /// 异步提交变化
        /// </summary>
        /// <returns></returns>
        Task<int> SaveChangesAsync();

        Task<int> SaveChangesAsync(CancellationToken cancellationToken);
    }
}
